package com.yuye.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Properties;

/**
 * 系统页面视图
 * 
 * @author yuye
 * @email yuyeweb@vip.qq.com
 * @date 2016年11月24日 下午11:05:27
 */
@Controller
public class SysPageController {
	@RequestMapping("sys/{url}.html")
	public String page(@PathVariable("url") String url,Model model){
		if("main".equals(url)){
			Properties props=System.getProperties(); //获得系统属性集
			Runtime r = Runtime.getRuntime();
			String osName = props.getProperty("os.name"); //操作系统名称
			String osArch = props.getProperty("os.arch"); //操作系统构架
			String osVersion = props.getProperty("os.version"); //操作系统版本
			String java = props.getProperty("java.version");//JDK 版本
			Long memory = r.totalMemory()/1024/1024;//总内存
			Long freeMemory = r.freeMemory()/1024/1024;//剩余内存
			Long useMemory = memory - freeMemory;
			int cpu = r.availableProcessors();//可用CPU线程数
			model.addAttribute("osName",osName);
			model.addAttribute("osArch",osArch);
			model.addAttribute("osVersion",osVersion);
			model.addAttribute("java",java);
			model.addAttribute("memory",memory);
			model.addAttribute("useMemory",useMemory);
			model.addAttribute("freeMemory",freeMemory);
			model.addAttribute("cpu",cpu);
			return "sys/main.jsp";
		}else if("index".equals(url)){
			return "index.html";
		}
		return "sys/" + url + ".html";
	}

	@RequestMapping("generator/{url}.html")
	public String generator(@PathVariable("url") String url){
		return "generator/" + url + ".html";
	}
}
